/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.core.facade.impl;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import com.teknei.acabus.FacadeException;
import com.teknei.acabus.ServiceException;
import com.teknei.acabus.core.entities.NavigationChild;
import com.teknei.acabus.core.entities.NavigationParent;
import com.teknei.acabus.core.entities.Role;
import com.teknei.acabus.core.facade.NavigationFacade;
import com.teknei.acabus.core.services.NavigationRolesService;
import com.teknei.acabus.core.services.NavigationService;

/**
 * Session Bean implementation class NavigationFacadeBean
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 */
/**
 * @author amaro
 *
 */
@Stateless
public class NavigationFacadeBean implements NavigationFacade {

	@EJB
	private NavigationService serviceNavigation;

	@EJB
	private NavigationRolesService serviceRolesNavigation;

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findRolesAllowed(com.teknei.acabus.core.entities.NavigationParent)
	 */
	@Override
	public List<Role> findRolesAllowed(NavigationParent parent) throws FacadeException{
		try {
			List<Role> list = serviceRolesNavigation.findRolesAllowed(parent);
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findRelatedRoles:"+e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findRolesAllowed(com.teknei.acabus.core.entities.NavigationChild)
	 */
	@Override
	public List<Role> findRolesAllowed(NavigationChild parent) throws FacadeException{
		try {
			List<Role> list = serviceRolesNavigation.findRolesAllowed(parent);
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findRelatedRoles:"+e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#saveNavigationParent(com.teknei.acabus.core.entities.NavigationParent)
	 */
	@Override
	public int saveNavigationParent(NavigationParent parent) throws FacadeException{
		try{
			int pk = serviceRolesNavigation.saveNavigationParent(parent);
			return pk;
		}catch (ServiceException e) {
			throw new FacadeException("Error in saveNavigationParent:" + e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#saveNavigationChild(com.teknei.acabus.core.entities.NavigationChild)
	 */
	@Override
	public int saveNavigationChild(NavigationChild child) throws FacadeException{
		try{
			int pk = serviceRolesNavigation.saveNavigationChild(child);
			return pk;
		}catch (ServiceException e) {
			throw new FacadeException("Error in saveNavigationChild:" + e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#updateNavigationParent(com.teknei.acabus.core.entities.NavigationParent)
	 */
	@Override
	public void updateNavigationParent(NavigationParent parent) throws FacadeException{
		try{
			serviceRolesNavigation.updateNavigationParent(parent);
		}catch (ServiceException e) {
			throw new FacadeException("Error in updateNavigationParent:" + e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#updateNavigationParentWithRoles(com.teknei.acabus.core.entities.NavigationParent)
	 */
	@Override
	public void updateNavigationParentWithRoles(NavigationParent parent) throws FacadeException{
		try{
			serviceRolesNavigation.updateNavigationParentWithRoles(parent);
		}catch (ServiceException e) {
			throw new FacadeException("Error in updateNavigationParent:" + e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#updateNavigationChildWithRoles(com.teknei.acabus.core.entities.NavigationChild)
	 */
	@Override
	public void updateNavigationChildWithRoles(NavigationChild child) throws FacadeException{
		try{
			serviceRolesNavigation.updateNavigationChildWithRoles(child);
		}catch (ServiceException e) {
			throw new FacadeException("Error in updateNavigationChildWithRoles:" + e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#updateNavigationChild(com.teknei.acabus.core.entities.NavigationChild)
	 */
	@Override
	public void updateNavigationChild(NavigationChild child) throws FacadeException{
		try{
			serviceRolesNavigation.updateNavigationChild(child);
		}catch (ServiceException e) {
			throw new FacadeException("Error in updateNavigationChild:" + e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#deleteNavigationParent(com.teknei.acabus.core.entities.NavigationParent)
	 */
	@Override
	public void deleteNavigationParent(NavigationParent parent) throws FacadeException{
		try{
			serviceRolesNavigation.deleteNavigationParent(parent);
		}catch (ServiceException e) {
			throw new FacadeException("Error in deleteNavigationParent:" + e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#deleteNavigationChild(com.teknei.acabus.core.entities.NavigationChild)
	 */
	@Override
	public void deleteNavigationChild(NavigationChild child) throws FacadeException{
		try{
			serviceRolesNavigation.deleteNavigationChild(child);
		}catch (ServiceException e) {
			throw new FacadeException("Error in deleteNavigationChild:" + e.getMessage(), e);
		}
	}
	
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findRoles()
	 */
	@Override
	public List<Role> findRoles() throws FacadeException {
		try {
			List<Role> list = serviceRolesNavigation.findRoles();
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findRoles:" + e.getMessage(), e);
		}

	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#saveRole(com.teknei.acabus.core.entities.Role)
	 */
	@Override
	public int saveRole(Role role) throws FacadeException {
		try {
			int pk = serviceRolesNavigation.saveRole(role);
			return pk;
		} catch (ServiceException e) {
			throw new FacadeException("Error in saveRole:" + e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#updateRole(com.teknei.acabus.core.entities.Role)
	 */
	@Override
	public void updateRole(Role role) throws FacadeException {
		try {
			serviceRolesNavigation.updateRole(role);
		} catch (ServiceException e) {
			throw new FacadeException("Error in updateRole:" + e.getMessage(),
					e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#deleteRole(com.teknei.acabus.core.entities.Role)
	 */
	@Override
	public void deleteRole(Role role)throws FacadeException {
		try{
			serviceRolesNavigation.deleteRole(role);
		}catch (ServiceException e) {
			throw new FacadeException("Error in updateRole:" + e.getMessage(),
					e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findNavigationParents(java.util.List)
	 */
	@Override
	public List<NavigationParent> findNavigationParents(List<Role> listRole)
			throws FacadeException {
		try {
			List<NavigationParent> listNavigation = serviceRolesNavigation
					.findNavigationParentsByRoles(listRole);
			return listNavigation;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findNavigationParents:"
					+ e.getMessage(), e);
		}

	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findNavigationParents()
	 */
	@Override
	public List<NavigationParent> findNavigationParents()
			throws FacadeException {
		try {
			List<NavigationParent> list = serviceNavigation
					.findNavigationParents();
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findNavigationParents:"
					+ e.getMessage(), e);
		}

	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findNavigationChilds()
	 */
	@Override
	public List<NavigationChild> findNavigationChilds()throws FacadeException{
		try {
			List<NavigationChild> list = serviceNavigation
					.findNavigationChilds();
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findNavigationChilds:"
					+ e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findNavigationChilds(java.util.List, int)
	 */
	@Override
	public List<NavigationChild> findNavigationChilds(List<Role> listRole,
			int idParent) throws FacadeException {
		try {
			List<NavigationChild> list = serviceNavigation
					.findNavigationChilds(idParent);
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findNavigationChilds:"
					+ e.getMessage(), e);
		}

	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.facade.NavigationFacade#findNavigationChilds(int)
	 */
	@Override
	public List<NavigationChild> findNavigationChilds(int idParent)
			throws FacadeException {
		try {
			List<NavigationChild> list = serviceNavigation
					.findNavigationChilds(idParent);
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findNavigationChilds:"
					+ e.getMessage(), e);
		}

	}

	/**
	 * @return the serviceNavigation
	 */
	public NavigationService getServiceNavigation() {
		return serviceNavigation;
	}

	/**
	 * @param serviceNavigation
	 *            the serviceNavigation to set
	 */
	public void setServiceNavigation(NavigationService serviceNavigation) {
		this.serviceNavigation = serviceNavigation;
	}

	/**
	 * @return the serviceRolesNavigation
	 */
	public NavigationRolesService getServiceRolesNavigation() {
		return serviceRolesNavigation;
	}

	/**
	 * @param serviceRolesNavigation
	 *            the serviceRolesNavigation to set
	 */
	public void setServiceRolesNavigation(
			NavigationRolesService serviceRolesNavigation) {
		this.serviceRolesNavigation = serviceRolesNavigation;
	}

}
